package com.xsb.customview.searchview;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        FlowLayout flowLayout = findViewById(R.id.flowLayout);
        Button btnAdd = findViewById(R.id.btn_add);
        List<String> data = new ArrayList<>();
        for (int i = 0; i < 20; i++) {
            data.add("历史"+i);
        }
        flowLayout.setData(data);

        flowLayout.setOnItemClickListener(new FlowLayout.OnItemClickListener() {
            @Override
            public void onItemClick(View v, int index) {
                System.out.println("数据"+data.get(index));
                Toast.makeText(MainActivity.this, data.get(index), Toast.LENGTH_SHORT).show();
            }
        });

        btnAdd.setOnClickListener(v -> {
            flowLayout.invalidate();
            List<String> ss = new ArrayList<>();
            for (int i = 0; i < 10; i++) {
                ss.add("添加的数据"+i);
            }
            flowLayout.setData(ss);
        });
    }
}